import request from '@/utils/request'

// 认证API - 改为直接导出login方法
export const login = (formData) => {
  return request({
    url: '/api/auth/login',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export const getUserInfo = () => {
  return request({
    url: '/api/auth/userinfo',
    method: 'get'
  })
}

// 航班飞机查询API
export const FlightApi = {
  // 获取航班航线信息
  getFlightRoutes (page = 1, pageSize = 15) {
    return request({
      url: '/flight/flight-routes',
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按航班号查询航线详情
  getFlightRouteDetail (flightNumber) {
    return request({
      url: `/flight/flight-routes/${flightNumber}`,
      method: 'get'
    })
  },

  // 获取航班飞机信息
  getFlightPlanes (page = 1, pageSize = 10) {
    return request({
      url: '/flight/planes',
      method: 'get',
      params: {
        page: page,
        pageSize: pageSize
      }
    })
  },

  // 按飞机编号查询
  getPlanesByAircraftId (cfno, page = 1, pageSize = 10) {
    return request({
      url: `/flight/planes/${cfno}`,
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按飞机机型查询
  getPlanesByAircraftType (cftp, page = 1, pageSize = 10) {
    return request({
      url: '/flight/planes/cftp',
      method: 'get',
      params: { cftp, page, pageSize }
    })
  },

  // 获取航班时间信息
  getFlightTimes (page = 1, pageSize = 15) {
    return request({
      url: '/flight/time',
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按航班号查询时间信息
  getFlightTimesByNumber (flightNumber, page = 1, pageSize = 15) {
    return request({
      url: '/flight/time/flightNumber',
      method: 'get',
      params: { flightNumber, page, pageSize }
    })
  },

  // 获取机场信息
  getAirports (page = 1, pageSize = 15) {
    return request({
      url: '/flight/airport',
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按中文名查询机场
  getAirportsByCnName (cnnm, page = 1, pageSize = 15) {
    return request({
      url: '/flight/airport/cnName',
      method: 'get',
      params: { cnnm, page, pageSize }
    })
  },

  // 按英文名查询机场
  getAirportsByEnName (ennm, page = 1, pageSize = 15) {
    return request({
      url: '/flight/airport/enName',
      method: 'get',
      params: { ennm, page, pageSize }
    })
  },

  // 获取所有航线变更历史
  getAllRouteHistories (page = 1, pageSize = 15) {
    return request({
      url: '/flight/route-histories',
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按航班号查询航线变更历史
  getRouteHistoriesByFlightNumber (flightNumber, page = 1, pageSize = 15) {
    return request({
      url: `/flight/route-histories/flight/${flightNumber}`,
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按变更后始发地查询
  getRouteHistoriesByNewDeparture (departure, page = 1, pageSize = 15) {
    return request({
      url: `/flight/route-histories/new-departure/${departure}`,
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按变更后目的地查询
  getRouteHistoriesByNewDestination (destination, page = 1, pageSize = 15) {
    return request({
      url: `/flight/route-histories/new-destination/${destination}`,
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按变更后经停站查询
  getRouteHistoriesByNewStopover (stopover, page = 1, pageSize = 15) {
    return request({
      url: `/flight/route-histories/new-stopover/${stopover}`,
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 获取行李转盘信息
  getBaggageBelts (page = 1, pageSize = 15) {
    return request({
      url: '/flight/blls-belts',
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按航班号查询行李转盘
  getBaggageBeltsByFlightId (flid, page = 1, pageSize = 15) {
    return request({
      url: `/flight/blls-belts/${flid}`,
      method: 'get',
      params: { page, pageSize }
    })
  }
}

// 登机口管理API
export const BoardingGateApi = {
  // 获取所有登机口信息
  getAllBoardingGates (page = 1, pageSize = 15) {
    return request({
      url: '/flight/boarding-gates',
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按航班号查询登机口信息
  getBoardingGatesByFlightId (flid, page = 1, pageSize = 15) {
    return request({
      url: `/flight/boarding-gates/flight/${flid}`,
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 按登机口编号查询登机口信息
  getBoardingGatesByCode (code, page = 1, pageSize = 15) {
    return request({
      url: `/flight/boarding-gates/code/${code}`,
      method: 'get',
      params: { page, pageSize }
    })
  },

  // 添加登机口信息
  addBoardingGate (data) {
    return request({
      url: '/flight/boarding-gates',
      method: 'post',
      data: data
    })
  },

  // 更新登机口信息
  updateBoardingGate (code, data) {
    return request({
      url: `/flight/boarding-gates/${code}`,
      method: 'put',
      data: data
    })
  },

  // 删除登机口信息
  deleteBoardingGate (code) {
    return request({
      url: `/flight/boarding-gates/${code}`,
      method: 'delete'
    })
  }
}
